package com.plian.system.controller.pm.property;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.dto.pm.property.DecisionReportDTO;
import com.plian.system.entity.pm.property.PropertyBasics;
import com.plian.system.entity.pm.property.PropertyMessageInfo;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.model.R;
import com.plian.system.service.hr.staff.IStaffFilesService;
import com.plian.system.service.pm.property.IPropertyBasicsService;
import com.plian.system.service.pm.property.IPropertyMessageInfoService;
import com.plian.system.service.pm.property.PorpertyBasicsService;
import com.plian.system.vo.pm.property.ProStaffInfoVO;
import com.plian.system.vo.pm.property.SmallPropertyBasicsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@Api(value = "PropertyBasicsController", tags = "产权基础信息接口")
@RestController
    @RequestMapping(value = "api/propertyBasics")
public class PropertyBasicsController extends BaseController {
    @Autowired
    PorpertyBasicsService porpertyBasicsService;

    @Autowired
    IPropertyBasicsService propertyBasicsService;


    @Autowired
    private IStaffFilesService staffFilesService;

    @Autowired
    private IPropertyMessageInfoService propertyMessageInfoService;

    @PostMapping(value = "/tree")
    @ApiOperation(value = "产权基础信息树形数据", notes = "")
    public ObjResult tree() throws Exception {
        return porpertyBasicsService.tree();
    }

    @PostMapping(value = "/simpleTree")
    @ApiOperation(value = "产权基础信息树形数据", notes = "")
    public ObjResult simpleTree() throws Exception {
        return porpertyBasicsService.simpleTree();
    }

//    @PostMapping(value = "/mixedTree")
//    public ObjResult mixedTree(@RequestBody MixTreeDto dto){
//        return porpertyBasicsService.mixedTree(dto);
//    }

    @PostMapping(value = "/findbyidAll")
    @ApiOperation(value = "产权基础信息根据id查询", notes = "传入pd")
    public ObjResult findbyidAll(@RequestBody PageData pd) throws Exception {
        return porpertyBasicsService.findbyidAll(pd);
    }
    @PostMapping(value = "/findbyid")
    @ApiOperation(value = "产权基础信息根据id查询", notes = "传入pd")
    public ObjResult findbyid(@RequestBody PageData pd) throws Exception {
        return porpertyBasicsService.findbyid(pd);
    }
    @PostMapping(value = "/orgListPage")
    @ApiOperation(value = "产权基础信息list", notes = "传入pd")
    public ListResult orgListPage(@RequestBody PageData pd) throws Exception {
        return porpertyBasicsService.orgListPage(pd);
    }
    @PostMapping(value = "/editByOrgId")
    @ApiOperation(value = "产权基础信息修改根据组织id", notes = "传入pd")
    public ObjResult editByOrgId(@RequestBody PageData pd) throws Exception {
        return porpertyBasicsService.editByOrgId(pd);
    }
    @PostMapping(value = "/editByOrgIdAll")
    @ApiOperation(value = "产权基础信息修改根据组织id")
    public ObjResult editByOrgIdAll() throws Exception {
        return porpertyBasicsService.editByOrgIdAll();
    }
    @RequestMapping(value = "/toExcel")
    @ApiOperation(value = "产权基础信息生成excel")
    public void toExcel(HttpServletResponse response) throws Exception {
        porpertyBasicsService.toExcel(new PageData(),response);
    }
    @PostMapping(value = "/reportList")
    @ApiOperation(value = "产权基础信息列表")
    public ListResult reportList(@RequestBody PageData pd) throws Exception {
        return porpertyBasicsService.reportList(pd);
    }
    @PostMapping(value = "/reportListPage")
    @ApiOperation(value = "产权基础信息列表分页")
    public ListResult reportListPage(@RequestBody PageData pd) throws Exception {
        return porpertyBasicsService.reportListPage(pd);
    }
    @PostMapping(value = "/findByorgId")
    @ApiOperation(value = "产权基础信息根据组织id")
    public ObjResult findByorgId(@RequestBody PageData pd) throws Exception {
        return porpertyBasicsService.findByorgId(pd);
    }
    @PostMapping(value = "/findByorgName")
    @ApiOperation(value = "产权基础信息根据组织名字")
    public ListResult findByorgName(@RequestBody PageData pd) throws Exception {
        return porpertyBasicsService.findByorgName(pd);
    }
    @PostMapping(value = "/listAll")
    @ApiOperation(value = "产权基础信息列表")
    public ListResult listAll() throws Exception {
        return porpertyBasicsService.listAll();
    }
    @PostMapping(value = "/toExcel")
    @ApiOperation(value = "产权基础信息生成excel")
//    @PassToken
    public void toExcel(@RequestBody PageData pd, HttpServletResponse response) throws Exception {
         porpertyBasicsService.toExcel(pd,response);
    }
    @PostMapping(value = "/toExcel1")
    @ApiOperation(value = "产权基础信息生成excel")
//    @PassToken
    public void toExcel1(@RequestBody PageData pd, HttpServletResponse response) throws Exception {
         porpertyBasicsService.toExcel1(pd,response);
    }

    @GetMapping(value = "/toExcelBasics/{id}")
//    @PassToken
    public void toExcelBasic(@PathVariable String id, HttpServletResponse response) throws Exception {
        porpertyBasicsService.toExcelBasics(id,response);
    }

    @PostMapping(value = "/relationTree")
    public ObjResult relationTree() throws Exception {
        return porpertyBasicsService.relationTree();
    }

    @PostMapping(value = "/simpleRelationTree")
    public ObjResult simpleRelationTree() throws Exception {
        return porpertyBasicsService.simpleRelationTree();
    }

    @GetMapping(value = "/initPropertyCode")
    public R initPropertyCode(){
        propertyBasicsService.initPropertyCode();
        return R.success();
    }

    @GetMapping(value = "/initIsPrivateMix")
    public R initIsPrivateMix(){
        propertyBasicsService.initIsPrivateMix();
        return R.success();
    }


    @GetMapping(value = "/getAllChildList")
    public  R<List<SmallPropertyBasicsVO>> getAllChildList(){
        return R.data(propertyBasicsService.getAllChildList());
    }

    @GetMapping(value = "/getAllPropertyMessage")
    public R<List<PropertyMessageInfo>> getAllPropertyMessage(){
        return R.data(propertyMessageInfoService.list());
    }

    @PostMapping(value = "/decisionReport")
    public R<Map<String, Object>> decisionReport(@RequestBody DecisionReportDTO dto){
        return R.data(propertyBasicsService.decisionReport(dto.getProId(),dto.getStartDate(), dto.getEndDate()));
    }

    @GetMapping("/name-like")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "模糊查询")
    })
    @ApiOperation("名字模糊查询")
    public R<List<PropertyBasics>> nameLikeList(@RequestParam(name = "name",required= false,defaultValue = "") String name){
        return R.data(propertyBasicsService.nameLikeList(name));
    }

    @GetMapping("/staff-info")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "proId", value = "产权id")
    })
    @ApiOperation("产权查询页面-人员信息")
    public R<ProStaffInfoVO> staffInfo(@RequestParam(name = "proId") String proId){
        return R.data(staffFilesService.staffInfo(proId));
    }
}
